package org.meruvian.yama.dao;

import java.util.List;

import org.meruvian.yama.dao.base.BaseDaoHibernate;
import org.meruvian.yama.entity.Person;
import org.springframework.stereotype.Repository;

/**
*
* @author vick
*/
@Repository
public class PersonDao extends BaseDaoHibernate<Person>{
	
	@SuppressWarnings("unchecked")
    public List<Person> listParent(String personId){
        return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where id != '"+personId+"' and relation_id != '"+personId+"' or relation_id = null ").list();
        //return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where id != '"+personId+"' and (relation_id != '"+personId+"' or relation_id = null) and parent_id != '"+personId+"' ").list();
    }
	
	@SuppressWarnings("unchecked")
    public List<Person> listChild(String personId, String parentId){
        return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where id != '"+personId+"' ").list();
        //return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where id != '"+personId+"' and relation_id != '"+personId+"' or relation_id = null and id != '"+parentId+"' ").list();
    }
	
	@SuppressWarnings("unchecked")
    public List<Person> listPerson(boolean sex){
        return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where relation_id = null and gender != "+sex+" ").list();
    }
	
	@SuppressWarnings("unchecked")
    public List<Person> findPerson(String firstName){
        return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where firstName like '%"+firstName+"%' ").list();
    }
	
	@SuppressWarnings("unchecked")
    public List<Person> getParentC(String id){
        return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where id = '"+id+"'").list();
    }
	
	@SuppressWarnings("unchecked")
    public List<Person> getChildP(String personId, String relationId){
		return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where parent_id = '"+personId+"' or parent_id = '"+relationId+"' ").list();
    }
	
}
